1. Field of the Invention
The invention relates in general to a calculator, and more particularly to a method and apparatus for managing an image memory in an embedded device.
2. Description of the Related Art
Direct Frame Buffer (DirectFB) is a prevalent software library implemented in embedded systems. Tailored for special requirement environments of embedded devices, DirectFB is a compact, powerful and easy-to-use technique for graphic acceleration and graphic reinforcement. Functions of DirectFB manage an image memory by use of a linked list. In an initial state, the linked list only includes one free memory node for recording a start address and an end address of an entire memory pool. When an application program needs to be allotted with a memory block from the memory pool, a DirectFB memory management unit traverses all free memory nodes in the linked list, and identifies and allots a most matching free memory node to the application program. In the event that no matching free memory node having an appropriate size is found, a free memory node having a closest size is allotted, a new memory node is inserted into the linked list to record information of the newly allotted memory block, and the new memory node is then marked as having been allotted. Memory blocks described in neighboring memory nodes in the linked list are also physically neighboring.
In current DirectFB techniques for managing the memory, when an application program releases a memory block, a node recording information of the memory block is set to free. When a neighboring node of the free node is also free, the two nodes are merged such that the free memory blocks recorded by the two nodes are merged into a larger free memory block, as indicated by a block block4 merged from the block block4 and a block block5 in FIG. 1. With the above memory management technology, memory fragments result if the physically continuous memory blocks have different lifespans. Thus, although a total amount of the free memory is greater than the size of the required memory, it is possible that all the free nodes are smaller than the size of the required memory to cause a memory allotment failure during the memory management.
Therefore, there is a need for a solution for ensuring an application program is allotted with a required memory under a situation that a free memory is greater than the required memory.